package com.calcs
{
	import com.adobe.air.logging.FileTarget;
	
	import flash.filesystem.*;
	
	import mx.collections.XMLListCollection;
	import com.calcs.logger.Logger;
	
	
	public class CalcsMain
	{
		private var menusXmlList:XMLListCollection;
		private var logger : Logger = Logger.getInstance("CalcsMain");
		
		public function getMenusXmlList():XMLListCollection
		{
			return this.menusXmlList;
		}
		public function CalcsMain()
		{
			initializeApplication();
		}
		private function initializeApplication():void
		{
			initializeMenus();
		}

		private function initializeMenus():void
		{
			logger.debug("Initializing the menus");
			var xmlContent:String = null;
			try
			{
				xmlContent = loadData(CalcConstants.MENUS_LOCATION);
			}
			catch(e:Error)
			{
				logger.error(e);
			}
			this.menusXmlList = new XMLListCollection(new XMLList(xmlContent));
			this.menusXmlList.refresh();
		}
		
		/**
		 * Load the xml file and read its data.
		 */
		private function loadData(fileLocation:String):String
		{
		  var dataFile:File = File.applicationDirectory.resolvePath(fileLocation);
		  var _data:String;
		  var stream:FileStream = new FileStream();
		  stream.open(dataFile, FileMode.READ);
		  _data = stream.readUTFBytes(stream.bytesAvailable);
		  stream.close();
		  return _data;
		}
	}
}